package com.pinyoumei.app.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.pinyoumei.app.R;
import com.pinyoumei.app.activity.wallet.WalletRechargeActivity;
import com.pinyoumei.app.utils.Utils;

public class HistorySubmitDialog extends Dialog implements View.OnClickListener {

    private Context context;
    private int type;
    private String num;


    public HistorySubmitDialog(Context context, int type, String num){
        super(context, R.style.dialogStyle);//这个决定dialog的样式
        this.context = context;
        this.type = type;
        this.num = num;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        Window window = getWindow();//获取一个窗口
        window.setGravity(Gravity.CENTER);//设置窗口的位置
//        window.setWindowAnimations(R.style.center_scale_animation);//设置窗口进入时的动画特效
        WindowManager.LayoutParams layoutParams = window.getAttributes();//获取窗口的属性赋值给layoutParams
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(layoutParams);//设置窗口的属性
        setCanceledOnTouchOutside(true);
        setContentView(R.layout.history_submit_dialog_view);
        TextView his_sub_title = findViewById(R.id.his_sub_title);
        TextView his_sub_content = findViewById(R.id.his_sub_content);
        TextView his_sub_num = findViewById(R.id.his_sub_num);
        TextView his_sub_company = findViewById(R.id.his_sub_company);
        TextView his_sub_cancel = findViewById(R.id.his_sub_cancel);
        TextView his_sub_determine = findViewById(R.id.his_sub_determine);
        his_sub_cancel.setOnClickListener(this);
        his_sub_determine.setOnClickListener(this);

        if (type == 1){
            his_sub_title.setText("转创业金");
            his_sub_content.setText("创业金实体开店可抵扣部分加盟费");
            his_sub_company.setText("(元）");
        }else if (type == 2){
            his_sub_title.setText("转积分");
            his_sub_content.setText("兑换积分之后，积分可在积分商城兑换您喜欢的商品");
            his_sub_company.setText("(个）");
        }
        his_sub_num.setText(num);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.his_sub_cancel:
                dismiss();
                break;
            case R.id.his_sub_determine:
                listener.btnonClick(type);
                dismiss();
                break;
        }
    }

    @Override
    public void show(){
        super.show();
        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
//        layoutParams.alpha=0.8f;
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);
    }

    private BtnOnClickListener listener;

    public void setListener(BtnOnClickListener listener) {
        this.listener = listener;
    }

    public interface BtnOnClickListener {
        void btnonClick(int type);
    }


}